import { useRequest } from "./config";

const { request } = useRequest();

export function useChatApi() {
  const createChat = async (chatDto) => {
    var res = await request({
      url: "/AIQuestions/user",
      method: "POST",
      data: chatDto,
      showLoading: true,
    });

    return res;
  };

  const getChat = async (id) => {
    var res = await request({
      url: `/AIQuestions/user/${id}`,
      method: "GET",
      data: null,
      showLoading: true,
    });

    return res;
  };

  const getAllMessage = async (id) => {
    var res = await request({
      url: `/AIQuestions/user/message/${id}`,
      method: "GET",
      data: null,
      showLoading: true,
    });

    return res;
  };

  const deleteChat = async (id) => {
    var res = await request({
      url: `/AIQuestions/user/${id}`,
      method: "DELETE",
      data: null,
      showLoading: true,
    });

    return res;
  };

  const conversation = async (id, userMessage) => {
    var res = await request({
      url: `/AIQuestions/chat/${id}`,
      method: "POST",
      data: JSON.stringify(userMessage),
      showLoading: true,
    });

    return res;
  };

  return { conversation, createChat, deleteChat, getAllMessage, getChat };
}
